<template>
  <!--首页头部 -->
  <div class="header-container">
    <!-- 首页头部左边的城市选择部分 -->
    <div class="header-left">
      <router-link to="/city"><p class="address">{{this.city}}</p></router-link>
      <img src="~assets/images/home/jiantou-btn.png" alt="">
    </div>

    <!-- 首页头部中间的搜索框部分 -->
    <div class="header-center">
      <div class="left">
        <p>商品</p>
        <img src="~assets/images/home/jiantou-btn.png" alt="">
      </div>
      <div class="center">
        <input type="text" placeholder="请输入关键字" @click="itemClick">
      </div>
      <div class="right ">
        <span class="iconfont">&#xe62d;</span>
      </div>
    </div>

    <!-- 首页头部的购物车图标部分 -->
    <div class="header-right ">
      <img src="~assets/images/home/cart-right.png" alt="" @click="goCart">
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'
export default {
  name: 'HomeHeader',
  computed: {
    ...mapState(['city'])
  },
  methods: {
    //点击搜索框去到搜索页面
    itemClick () {
      this.$router.push('/search')
    },
    //点击首页购物车图标跳转到购物页面
    goCart () {
      this.$router.push('/cart')
    },
  }
}
</script>

<style lang="less" scoped>
.header-container {
  display: flex;
  height: .44rem;
  line-height: .44rem;
  background: #fff;
  .header-left {
    p {
      float: left;
      color: #333;
      max-width: .3rem;
      overflow: hidden;
      text-overflow:ellipsis;
      white-space: nowrap;
      margin-left: .15rem;
      font-size: .14rem;
    }
    img {
      display: inline-block;
      width: .08rem;
      height: .05rem;
      margin-left: .05rem;
    }
  }
  .header-center {
    width: 2.05rem;
    height: .3rem;
    display: flex;
    line-height: .3rem;
    margin-top: .07rem;
    align-content: center;
    margin-left: .215rem;
    border: 1px solid #ccc;
    border-radius: .15rem;
    .left {
     display: flex;
     margin-left: .185rem;
      p {
        font-size: .14rem;
        color: #333;
        display: block;
        margin-bottom: .18rem;
      }
      img {
        width: .08rem;
        height: .05rem;
        margin-top: .135rem;
        margin-left: .055rem;
        margin-right: .085rem;
        display: inline-block;
      }
    }
    .center {
      input {
      width: .84rem;
      height: .13rem;
      font-size: .14rem;
      margin-top: -.04rem;
      }
    }
  }
  .right {
    span {
      display: inline-block;
      width: .2rem;
      height: .19rem;
      margin-left: .225rem;
      position: relative;
      top: -.02rem;
    }
  }
  .header-right {
    margin-left: .39rem;
    img {
      display: inline-block;
      width: .2rem;
      height: .19rem;
    }
  }
}
</style>
